package main

import (
	"sync"
	"fmt"
	"time"
)

type SafeCounter struct {
	mutex sync.Mutex
	val   int
}
type ThreadCunter interface {
	get() int
	increase(val int)
}

func (this* SafeCounter) get() int {
	this.mutex.Lock()
	defer this.mutex.Unlock()
	return this.val
}
func (this* SafeCounter) increase(val int) {
	this.mutex.Lock()
	this.val += val
	println(this.val)
	this.mutex.Unlock()
}

func main() {
	var a = &SafeCounter{}
	for i := 0; i < 10; i++ {
		go func(data int) {
			a.increase(data)
		}(i)
	}
	for {
		time.Sleep(time.Second)
		fmt.Println(a.get())
		return
	}

}
